<html>
	<?php
		require_once("classes/User.php");
		require_once("classes/Database.php");
		require_once("classes/Head.php");
		require_once("classes/Section.php");
		require_once("classes/Image.php");
		require_once("classes/Title.php");
		require_once("classes/Paragraph.php");
		require_once("classes/LinkList.php");
		require_once("classes/Form.php");
		
		session_start();
		
		$head = new Head();
		$user = $_SESSION["user"];
		$db = new Database("localhost", "root", "");
		$db->connect("emprego");
		
		$id = $user->getId();
		
		$db->executeQuery("SELECT * FROM curriculum WHERE id='$id'");
		
		if($line = $db->getResultLine(MYSQL_ASSOC)){
			$category = $line["category"];
			$description = $line["description"];
		}
		
		if($_SESSION["login"]){
			$title = "Criar/Modificar C.V";
		}else{
			$title = "Login Errado";
		}
		$head->addLayout("css/style.css");
		$head->addTitle($title);
		
		$head->printHead();
	?>
	<body id="body">
		<div id="struture">
			<div id="container">
		        <?php
		        	$header = new Section("header");					
						$header->addElement(new Image("images/job.png", "logo", "100px", "100px"));
						
						$title = new Title("Ofertas de Emprego", "title");
						$header->addElement($title);
					$header->printSection();
		        	
		        	/* Left Page */
		        	$leftPage = new Section("leftPage");
					if(!$_SESSION["login"]){
						$leftPage->addElement(new Title("Erro", "menuTitle"));
						$leftPage->addElement(new Paragraph("Login Errado", "menu"));
					}else{
						$leftPage->addElement(new Title("Ajuda", "menuTitle"));
						$leftPage->addElement(new Paragraph("Introduza os dados do C.V no formul&aacuterio, todos os dados s&atildeo obrigat&oacuterios.", "menu"));
						$voltar = new LinkList("menuEntry");
						$voltar->addLink("Logout", "scripts/logout.php", new Image("images/leave.png", "icon", "16px", "16px"));
						$voltar->addLink("Voltar", "home.php", new Image("images/leave.png", "icon", "16px", "16px"));
						$leftPage->addElement($voltar);
						if(isset($category)){
							$leftPage->addElement(new Title("Informa&ccedil&otildees", "menuTitle"));
							$dataElements = new LinkList("menuEntry");
							$dataElements->addLink("Adicionar Habilita&ccedil&atildeo", "addQualifications.php", new Image("images/add.png", "icon", "16px", "16px"));
							$dataElements->addLink("Adicionar Experi&ecircncia", "addExperience.php", new Image("images/add.png", "icon", "16px", "16px"));
							$dataElements->addLink("Modificar Habilita&ccedil&atildeo", "changeQualifications.php", new Image("images/doc_tool.png", "icon", "16px", "16px"));
							$dataElements->addLink("Modificar Experi&ecircncia", "changeExperiences.php", new Image("images/doc_tool.png", "icon", "16px", "16px"));
							$leftPage->addElement($dataElements);
						}
					}
					$leftPage->printSection();

					$content = new Section("content");
					
					if($_SESSION["login"]){
						$content->addElement(new Title("Criar/Modificar Curriculum Vitae", "seccaoTitle"));
	
						$form = new Form("scripts/validateCV.php", "POST", "formTable");
						$form->openSelect("Categoria:", "input", "category");
						if(!isset($category)){
							$db->executeQuery("SELECT id, name FROM category");
							while($line = $db->getResultLine(MYSQL_ASSOC)){
								$form->addOption($line["id"], $line["name"], FALSE);
							}
						}else{
							$db->executeQuery("SELECT id, name FROM category WHERE id='$category'");
							$line = $db->getResultLine(MYSQL_ASSOC);
							$form->addOption($line["id"], $line["name"], TRUE);
							$db->executeQuery("SELECT id, name FROM category WHERE id<>'$category'");
							while($line = $db->getResultLine(MYSQL_ASSOC)){
							$form->addOption($line["id"], $line["name"], FALSE);								
							}
						}
						$form->closeSelect();
						if(isset($description)){
							$form->addTextArea("Decri&ccedil&atildeo:", "inputarea", "description", $description, 8, 50, TRUE);
						}else{
							$form->addTextArea("Decri&ccedil&atildeo:", "inputarea", "description", "", 8, 50, TRUE);
						}
						$form->addInput("", "submit", "", "button", "Gravar", "", TRUE);
											
						$content->addElement($form);
					}else{
						$content->addElement(new Title("Erro", "seccaoTitle"));
					}
					$content->printSection();
					
					$footer = new Section("footer");
						$text = new Paragraph("Copyright&copy Nuno Pombo", "");
						$footer->addElement($text);
					$footer->printSection();
		        ?>
			</div>
		</div>
	</body>
</html>